package com.we823.cms.common.web.pageable;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * Created by ZhangYinxian on 2016-10-20.
 */
public class PageRequest {
    private Integer pageSize = 0;
    private Integer pageNum = 0;
    private String column;
    private String directionName;
    private Sort sort;
    private List<Sort> sortList = Lists.newArrayList();
    private Direction direction;
    /**
     * 标记是否需要计算count
     */
    private boolean countable = true;

    public PageRequest() {
    }

    /**
     * 分页信息
     * @param pageNum 页码
     * @param pageSize 每页的条数
     */
    public PageRequest(Integer pageNum, Integer pageSize) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
    }

    public PageRequest(Integer pageNum, Integer pageSize, String column, String directionName) {
        this(pageNum, pageSize, new Sort(column, directionName));
    }


    public PageRequest(Integer pageNum, Integer pageSize, Direction direction, String column) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.column = column;
        this.direction = direction;
        this.sort = new Sort(direction, column);
    }

    public PageRequest(Integer pageNum, Integer pageSize, Sort sort) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.sort = sort;
        if (sort != null) {
            this.column = sort.getColumn();
            this.directionName = sort.getDirection().getName();
        }
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public String getColumn() {
        return column;
    }

    public void setColumn(String column) {
        this.column = column;
    }

    public Sort getSort() {
        return sort;
    }

    public void setSort(Sort sort) {
        this.sort = sort;
    }

    public String getDirectionName() {
        return directionName;
    }

    public void setDirectionName(String directionName) {
        this.directionName = directionName;
    }

    public Direction getDirection() {
        return direction;
    }

    public void setDirection(Direction direction) {
        this.direction = direction;
    }

    public boolean getCountable() {
        return countable;
    }

    public void setCountable(boolean countable) {
        this.countable = countable;
    }

    public List<Sort> getSortList() {
        return sortList;
    }

    public void setSortList(List<Sort> sortList) {
        this.sortList = sortList;
    }
}
